﻿using Model;
using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using FubiManger.Controls;

namespace FubiManger.UI
{
    partial class ClearcodeForm : Smobiler.Core.Controls.MobileForm
    {
        public ClearcodeForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        List<ms_order> codelist = new List<ms_order>();
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ClearcodeForm_Load(object sender, EventArgs e)
        {
            codelist = orderDal.Querycodes(merchantid);//查待核销订单
            Getorder(codelist);
        }
        /// <summary>
        /// 获取订单
        /// </summary>
        private void Getorder(List<ms_order> ordlist)
        {
            if (panorder.Controls.Count > 0)
                panorder.Controls.Clear();
            for (int i = 0; i < ordlist.Count; i++)
            {
                ordercontrol1 con = new ordercontrol1();
                con.disksn = ordlist[i].orderdisksn;//桌号
                con.ordsn = ordlist[i].order_sn;//订单号
                con.ordtime = ordlist[i].add_time;
                con.nickname = ordlist[i].user_tel.Substring(0, 3) + "****" + ordlist[i].user_tel.Substring(7, 4);
                con.ordid = ordlist[i].id;//编号
                con.codestatus = ordlist[i].codestatus;//核销状态
                con.stype = "2";
                panorder.Controls.Add(con);
            }
        }
        /// <summary>
        /// 刷新
        /// </summary>
        public void Refsh()
        {
            codelist = orderDal.Querycodes(merchantid);//查待核销订单
            Getorder(codelist);
        }

        private void button2_Press(object sender, EventArgs e)
        {
            if (button2.Text == "时间降序")
            {
                button2.Text = "时间升序";
                List<ms_order> rdlist = codelist.OrderBy(a => a.id).ToList();
                Getorder(rdlist);
            }
            else
            {
                button2.Text = "时间降序";
                List<ms_order> rdlist = codelist.OrderByDescending(a => a.id).ToList();
                Getorder(rdlist);
            }
        }
    }
}